package com.neuedu.yunong.controller;

import java.util.List;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neuedu.common.annotation.Log;
import com.neuedu.common.core.controller.BaseController;
import com.neuedu.common.core.domain.AjaxResult;
import com.neuedu.common.enums.BusinessType;
import com.neuedu.yunong.domain.YunongFamilyInfo;
import com.neuedu.yunong.service.IYunongFamilyInfoService;
import com.neuedu.common.utils.poi.ExcelUtil;
import com.neuedu.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 家庭经济Controller
 * 
 * @author ruoyi
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/family/economies")
@Tag(name = "【家庭经济】管理")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class YunongFamilyInfoController extends BaseController
{
    private final IYunongFamilyInfoService yunongFamilyInfoService;

    /**
     * 查询家庭经济列表
     */
    @Operation(summary = "查询家庭经济列表")
    @PreAuthorize("@ss.hasPermi('family:economies:list')")
    @GetMapping("/list")
    public TableDataInfo list(YunongFamilyInfo yunongFamilyInfo)
    {
        startPage();
        List<YunongFamilyInfo> list = yunongFamilyInfoService.selectYunongFamilyInfoList(yunongFamilyInfo);
        return getDataTable(list);
    }

    /**
     * 导出家庭经济列表
     */
    @Operation(summary = "导出家庭经济列表")
    @PreAuthorize("@ss.hasPermi('family:economies:export')")
    @Log(title = "家庭经济", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YunongFamilyInfo yunongFamilyInfo)
    {
        List<YunongFamilyInfo> list = yunongFamilyInfoService.selectYunongFamilyInfoList(yunongFamilyInfo);
        ExcelUtil<YunongFamilyInfo> util = new ExcelUtil<YunongFamilyInfo>(YunongFamilyInfo.class);
        util.exportExcel(response, list, "家庭经济数据");
    }

    /**
     * 获取家庭经济详细信息
     */
    @Operation(summary = "获取家庭经济详细信息")
    @PreAuthorize("@ss.hasPermi('family:economies:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yunongFamilyInfoService.selectYunongFamilyInfoById(id));
    }

    /**
     * 新增家庭经济
     */
    @Operation(summary = "新增家庭经济")
    @PreAuthorize("@ss.hasPermi('family:economies:add')")
    @Log(title = "家庭经济", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YunongFamilyInfo yunongFamilyInfo)
    {
        return toAjax(yunongFamilyInfoService.insertYunongFamilyInfo(yunongFamilyInfo));
    }

    /**
     * 修改家庭经济
     */
    @Operation(summary = "修改家庭经济")
    @PreAuthorize("@ss.hasPermi('family:economies:edit')")
    @Log(title = "家庭经济", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YunongFamilyInfo yunongFamilyInfo)
    {
        return toAjax(yunongFamilyInfoService.updateYunongFamilyInfo(yunongFamilyInfo));
    }

    /**
     * 删除家庭经济
     */
    @Operation(summary = "删除家庭经济")
    @PreAuthorize("@ss.hasPermi('family:economies:remove')")
    @Log(title = "家庭经济", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) 
    {
        return toAjax(yunongFamilyInfoService.deleteYunongFamilyInfoByIds(ids));
    }
}
